package Psy_Admin_Page;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

//封装了咨询师和督导共有的一些方法

public class StaffPage extends GuestPage{
    //新增督导 & 咨询师
    //咨询师&督导点击新增
    public StaffPage clickAdd(){
        waitForWindow(2000);
        driver.findElement(By.cssSelector(".addBtn")).click();
        return this;
    }

    //点击修改 默认第一个
    public StaffPage clickEdit(){
        return this;
    }

    /** 直接通过findElement方法获取某个元素，如果该元素不存在肯定会报错，
     *  selenium又没有可以判断该元素是否存在的方法，
     *  于是我们可以手写一个工具类，来判断这个元素是否存在
     *  判断某个元素是否存在,存在返回true,否则false
     */
    public boolean isElementExist(WebDriver driver, By by) {
        try {
            WebElement element = driver.findElement(by);
            //System.out.println(element.getText());
            return true;
        } catch (Exception e) {
            //System.out.println("不存在此元素");
            return false;
        }
    }

    //输入姓名
    public StaffPage inputName(String keys){
        waitForWindow(2000);
        driver.findElement(By.xpath("(//input[@type='text'])[4]")).click();
        driver.findElement(By.xpath("(//input[@type='text'])[4]")).sendKeys(keys);
        return this;
    }

    //修改姓名
    public StaffPage editName(String keys){
        waitForWindow(2000);
        //点击clear
        //.el-icon-circle-close
        driver.findElement(By.xpath("(//input[@type='text'])[4]")).click();
        driver.findElement(By.cssSelector(".el-icon-circle-close")).click();
        //重新输入
        inputName(keys).confirmAdd();
        return this;
    }

    //获取第一个用户的姓名
    public String getName(){
        waitForWindow(1000);
        return driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(1) > div:nth-child(1) > div:nth-child(1) > span:nth-child(2)")).getText();
    }

    //输入电话号码
    public StaffPage inputPhoneNum(String keys){
        waitForWindow(2000);
        driver.findElement(By.xpath("(//input[@type='text'])[5]")).click();
        driver.findElement(By.xpath("(//input[@type='text'])[5]")).sendKeys(keys);
        return this;
    }

    //修改电话
    public StaffPage editPhoneNum(String keys){
        waitForWindow(2000);
        //点击clear
        driver.findElement(By.xpath("(//input[@type='text'])[5]")).click();
        driver.findElement(By.cssSelector(".el-icon-circle-close")).click();
        //重新输入
        inputPhoneNum(keys).confirmAdd();
        return this;
    }

    //获取第一个用户的电话
    public String getPhoneNum(){
        return driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(4) > div:nth-child(1) > span:nth-child(1)")).getText();
    }

    //输入身份证号
    public StaffPage inputID(String keys){
        waitForWindow(2000);
        driver.findElement(By.xpath("(//input[@type='text'])[6]")).click();
        driver.findElement(By.xpath("(//input[@type='text'])[6]")).sendKeys(keys);
        return this;
    }

    //修改身份证号
    public StaffPage editID(String keys){
        waitForWindow(2000);
        //点击clear
        driver.findElement(By.xpath("(//input[@type='text'])[6]")).click();
        driver.findElement(By.cssSelector(".el-icon-circle-close")).click();
        //重新输入
        inputID(keys).confirmAdd();
        return this;
    }

    //获取第一个用户的性别
    public String getSex(){
        return driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(2) > div:nth-child(1) > span:nth-child(1)")).getText();
    }

    //输入邮箱
    public StaffPage inputEMail(String keys){
        waitForWindow(2000);
        driver.findElement(By.xpath("(//input[@type='text'])[7]")).click();
        driver.findElement(By.xpath("(//input[@type='text'])[7]")).sendKeys(keys);
        return this;
    }

    //修改Email
    public StaffPage editEmail(String keys){
        waitForWindow(2000);
        //点击clear
        driver.findElement(By.xpath("(//input[@type='text'])[7]")).click();
        driver.findElement(By.cssSelector(".el-icon-circle-close")).click();
        //重新输入
        inputEMail(keys).confirmAdd();
        return this;
    }

    //获取邮箱
    public String getEmail(){
        return driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(5) > div:nth-child(1) > span:nth-child(1)")).getText();
    }

    //输入职称
    public StaffPage inputJobTitle(String keys){
        return this;
    }

    //修改职称
    public StaffPage editJobTitle(String keys){
        return this;
    }

    //获取职称
    public String getJobTitle(){
        return driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(6) > div:nth-child(1) > span:nth-child(1)")).getText();
    }


    //输入资质编号
    public StaffPage inputQualityNum(String keys){
        waitForWindow(2000);
        driver.findElement(By.xpath("(//input[@type='text'])[10]")).click();
        driver.findElement(By.xpath("(//input[@type='text'])[10]")).sendKeys(keys);
        return this;
    }

    //修改资质编号
    public StaffPage editQualityNum(String keys){
        waitForWindow(2000);
        //点击clear
        driver.findElement(By.xpath("(//input[@type='text'])[10]")).click();
        driver.findElement(By.cssSelector(".el-icon-circle-close")).click();
        //重新输入
        inputQualityNum(keys).confirmAdd();
        return this;
    }

    //获取资质编号
    public String getQualityNum(){
        //进入到修改页面看是否有实质的修改
        waitForWindow(2000);
        clickEdit();
        waitForWindow(2000);
        //获取当前资质编号输入框内的值
       return driver.findElement(
                By.cssSelector("div.el-row:nth-child(4) > div:nth-child(2) > " +
                        "div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > input:nth-child(1)")).getAttribute("value");
    }

    //输入工作单位
    public StaffPage inputWorkPlace(String keys){
        return this;
    }

    //修改工作单位
    public StaffPage editWorkplace(String keys){
        return this;
    }

    //获取工作单位
    public String getWorkplace(){
        return driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(7) > div:nth-child(1) > span:nth-child(1)")).getText();
    }

    //输入用户名
    public StaffPage inputUsername(String keys){
        waitForWindow(2000);
        driver.findElement(By.xpath("(//input[@type='text'])[12]")).click();
        driver.findElement(By.xpath("(//input[@type='text'])[12]")).sendKeys(keys);
        return this;
    }

    //修改用户名
    public StaffPage editUsername(String keys){
        waitForWindow(2000);
        //点击clear
        driver.findElement(By.xpath("(//input[@type='text'])[12]")).click();
        driver.findElement(By.cssSelector(".el-icon-circle-close")).click();
        //重新输入
        inputUsername(keys).confirmAdd();
        return this;
    }

    //获取用户名
    public String  getUsername(){
        return driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(3) > div:nth-child(1) > span:nth-child(1)")).getText();
    }

    //输入密码
    public StaffPage inputPassword(String keys){
        waitForWindow(2000);
        driver.findElement(By.xpath("//input[@type='password']")).click();
        driver.findElement(By.xpath("//input[@type='password']")).sendKeys(keys);
        return this;
    }

    //修改用户名
    public StaffPage editPassword(String keys){
        waitForWindow(2000);
        //重新输入
        inputPassword(keys).confirmAdd();
        return this;
    }

    //确认修改信息
    public StaffPage confirmAdd() {
        driver.findElement(By.cssSelector(".el-dialog__footer:nth-child(3) .confirm")).click();
        return this;
    }

    //取消修改信息
    public StaffPage cancelAdd(){
        driver.findElement(By.cssSelector(".el-dialog__footer:nth-child(3) .cancel")).click();
        return this;
    }

    //咨询师&督导的修改排班功能

    //点击修改排班button
    public StaffPage editSchedule(){
        //默认修改第一个
        driver.findElement(By.cssSelector("tr.el-table__row:nth-child(1) > td:nth-child(10) > div:nth-child(1) > div:nth-child(1) > button:nth-child(2)")).click();
        //driver.findElement(By.xpath("//button[contains(.,'修改排班')]")).click();
        return this;
    }

    //选择周值班天数 day表示周几
    public StaffPage pickDay(String day){
        driver.findElement(By.cssSelector(".arrangementRow > .el-button:nth-child("+day+")")).click();
        waitForWindow(1000);
        return this;
    }

    //修改排班时的确定
    public StaffPage confirmEdit(){
        waitForWindow(2000);
        driver.findElement(By.cssSelector("div.el-dialog__footer:nth-child(3) > div:nth-child(1) > button:nth-child(2) > span:nth-child(1)")).click();
        return this;
    }

    //修改排班时的取消
    public StaffPage cancelEdit(){
        waitForWindow(2000);
        driver.findElement(By.cssSelector("div.el-dialog__footer:nth-child(3) > div:nth-child(1) > button:nth-child(1) > span:nth-child(1)")).click();
        return this;
    }

}
